import os
import re
import json
# 合并json成一个文件
p = 'job/static/js/map/js'
jsonp = 'job/static/json/province/'
js = os.listdir(p)
print(js)

all = {}
for f in js:
    ab = os.path.join(p,f)
    pinyin = f.split(".")[0]
    with open(ab,"r",encoding='utf-8') as file:
        s = file.read()
        
        province = re.findall("echarts.registerMap\\('(.*?)',",s)[0]
        print(pinyin,province)
        # 合成一个json
        # os.rename(os.path.join())
        # 这些不用点进去的
        if pinyin in ['beijing','aomen','taiwan','tianjin','xianggang','shanghai','chongqing']:
            continue
        with open(os.path.join(jsonp,pinyin+".json"),'r',encoding='utf-8') as jo:
            data =  json.loads( jo.read())
            all[province] = data

with open("provinces.json","w",encoding='utf-8') as out:
    out.write(json.dumps(all))



